import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JPanel;

/**
 * 
 */

/**
 * @author FTW nt
 *
 */
public class Background extends JPanel {
	int bx;
	Image img;
	int[] frame = {0 , 400 , 800 , 1200 , 1600 , 2000, 2400};

	public Background(int startPositionx){ 
		bx = startPositionx;
		ImageIcon i = new ImageIcon("C:/background.gif");		
		img = i.getImage();
	}
	
	public void move(int newX){
		bx = newX;		
	}
	
	public void paint( Graphics g){
		super.paint(g);
		Graphics2D g2d = (Graphics2D) g;		
			
		for(int r = 0; r < 6; r++){
			if((bx % frame[r + 1]) == 0){
				frame[r] = frame[r] + 2000;
			}
		}		
		g2d.drawImage(img, -bx + frame[0], 0, null);
		g2d.drawImage(img, -bx + frame[1], 0, null);
		g2d.drawImage(img, -bx + frame[2], 0, null);
		g2d.drawImage(img, -bx + frame[3], 0, null);
		g2d.drawImage(img, -bx + frame[4], 0, null);
		g2d.drawImage(img, -bx + frame[5], 0, null);
		g2d.drawImage(img, -bx + frame[0], 400, null);
		g2d.drawImage(img, -bx + frame[1], 400, null);
		g2d.drawImage(img, -bx + frame[2], 400, null);
		g2d.drawImage(img, -bx + frame[3], 400, null);
		g2d.drawImage(img, -bx + frame[4], 400, null);
		g2d.drawImage(img, -bx + frame[5], 400, null);
		
		System.out.println( bx );
					
	}
	
	
}
